package com.suning.sawp.service.impl.job;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.collect.Maps;
import com.suning.framework.dal.client.DalClient;

public class DBBIDeleteJob {
    @Autowired
    DalClient dalClient;

    private static interface DalExecutor {
        int execute(Map<String, Object> paramMap);
    }

    private int delete(int limit, DalExecutor executor) {
        Map<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("limit", limit);
        int affected = limit;
        int total = 0;
        while (!(affected < limit)) {
            affected = executor.execute(paramMap);
            total += affected;
        }
        return total;
    }
    
    /**
     * 删除
     */
    public int deleteBIIndexTaskCard(final String bizKey) {
        int limit = 1000;
        return delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                paramMap.put("bizKey", bizKey);
                return dalClient.execute("BI_JOB.delete_TABLE_INDEX_TASK_CARD_BY_BIZ_KEY", paramMap);
            }
        });
    }
    
    public int deleteBIModelAnalyse() {
        int limit = 1000;
        return delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAll_TABLE_MODEL_ANALYSE", paramMap);
            }
        });
    }
    
    public int deleteBISaleAnalyse() {
        int limit = 1000;
        return delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAll_TABLE_SALE_ANALYSE", paramMap);
            }
        });
    }
    
    public int deleteBIModelRecommend(){
        int limit = 1000;
        return delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAll_TABLE_MODEL_RECOMMEND", paramMap);
            }
        });
    }
    
    public int deleteBIModelCompanyRecommend(){
        int limit = 1000;
        return delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAll_TABLE_MODEL_COMPANY_RECOMMEND", paramMap);
            }
        });
    }
    
    public int deleteBIModelAreaRecommend(){
        int limit = 1000;
        return delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAll_TABLE_MODEL_AREA_RECOMMEND", paramMap);
            }
        });
    }
    
    public int deleteBIModelSaleTop(){
        int limit = 1000;
        return delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAll_TABLE_MODEL_SALE_TOP", paramMap);
            }
        });
    }
    
    public int deleteBIModelSaleTopIn(final String saleMonth){
        int limit = 1000;
        return delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                paramMap.put("saleMonth", saleMonth);
                return dalClient.execute("BI_JOB.DELETEALL_TABLE_MODEL_SALE_TOP_IN", paramMap);
            }
        });
    }

    /**
     * 删除
     */
    public int deleteBiStoreRealIncDetail() {
        int limit = 1000;
        return delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAllBiStoreRealIncDetailMEntity", paramMap);
            }
        });
    }

    /**
     * 删除
     */
    public void deleteOos() {
        int limit = 1000;
        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAll_TABLE_BI_STORE_GENERAL_OOS", paramMap);
            }
        });

        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAll_TABLE_BI_STORE_MAIN_PUSH_OOS", paramMap);
            }
        });

        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAll_TABLE_BI_STORE_HOT_OOS", paramMap);
            }
        });
    }

    /**
     * 删除
     */
    public void deleteOosDetail() {
        int limit = 1000;
        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.deleteAll_TABLE_BI_STORE_OOS_DETAIL", paramMap);
            }
        });
    }
    
    public void deleteStoreLastYearSale(final String today) {
        int limit = 1000;
        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                paramMap.put("statisDate", today);
                return dalClient.execute("BI_JOB.DELETE_STORE_LAST_YEAR_SALE", paramMap);
            }
        });
    }
    
    public void deleteStoreCateLastYearSale(final String today) {
        int limit = 1000;
        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                paramMap.put("statisDate", today);
                return dalClient.execute("BI_JOB.DELETE_STORE_CATE_LAST_YEAR_SALE", paramMap);
            }
        });
    }
    
    /**
     * 
     * 功能描述: <br>
     * 删除员工雇佣信息
     *
     */
    public void deleteEmployeeHireInfo(){
    	int limit = 1000;
        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.DELETE_EMPLOYEE_HIRE_INFO", paramMap);
            }
        });
    }
    
    /**
     * 
     * 功能描述: <br>
     * 删除员工首次销售信息
     *
     */
    public void deleteEmployeeFirstSaleInfo(){
    	int limit = 1000;
        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.DELETE_EMPLOYEE_FIRST_SALE_INFO", paramMap);
            }
        });
    }
    
    /**
     * 
     * 功能描述: <br>
     * 删除员工总销售信息
     *
     */
    public void deleteEmployeeTotalSaleInfo(){
    	int limit = 1000;
        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.DELETE_EMPLOYEE_TOTAL_SALE_INFO", paramMap);
            }
        });
    }
    
    /**
     * 
     * 功能描述: <br>
     * 删除员工最贵的销售信息
     *
     */
    public void deleteEmployeeExpensiveSaleInfo(){
    	int limit = 1000;
        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.DELETE_EMPLOYEE_EXPENSIVE_SALE_INFO", paramMap);
            }
        });
    }
    
    /**
     * 
     * 功能描述: <br>
     * 删除员工最贵的销售信息
     *
     */
    public void deleteEmployeeCategoryInfo(){
    	int limit = 1000;
        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.DELETE_EMPLOYEE_CATEGORY_INFO", paramMap);
            }
        });
    }
    
    /**
     * 
     * 功能描述: <br>
     * 删除员工2016年接待的客户信息
     *
     */
    public void deleteEmployeeMemberInfo(){
    	int limit = 1000;
        delete(limit, new DalExecutor() {
            @Override
            public int execute(Map<String, Object> paramMap) {
                return dalClient.execute("BI_JOB.DELETE_EMPLOYEE_MEMBER_INFO", paramMap);
            }
        });
    }
}
